package com.zb_study.method;

public class ThreadMethod01 {
    public static void main(String[] args) throws InterruptedException {
        T t = new T();
        t.setName("刘源");
        t.setPriority(Thread.MIN_PRIORITY);
        t.start();

        for (int i = 0; i < 5; i++) {
            Thread.sleep(1000);
            System.out.println("hi " +i);
        }

        System.out.println(t.getName()+"线程的优先级="+t.getPriority()); //1

        t.interrupt(); //当执行到这里，就会中断 t线程的休眠

    }
}

class T extends Thread {
    @Override
    public void run() {
        while (true) {
            for (int i = 0; i < 100; i++) {
                //Thread.currentThread().getName()  获取当前线程的名称
                System.out.println(Thread.currentThread().getName() + "吃包子...." + i);
            }
            System.out.println(Thread.currentThread().getName() + "休眠中....");
            try {
                Thread.sleep(20000);
            } catch (InterruptedException e) {
                //当该线程执行到一个interrupt 方法时，就会catch 一个 异常，可以加入自己的业务代码
                //InterruptedException 是捕获到一个中断异常
                System.out.println(Thread.currentThread().getName() + "被 interrupt了");
            }
        }
    }
}